package com.demoLearn;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: tutu
 **/
class java_collection{
    public static void main(String[] args) {

        //无需 不重复
      /*  Set<String> sets=new HashSet<>();
        sets.add("cyy");
        sets.add("cyy");
        sets.add("cyy1");
        if(sets.contains(null)){
            System.out.println("shitutuya:"+6666);
        }
        System.out.println("shitutuya:"+sets.size());*/


        //for循环测试   下标可以不右移
       /* boolean flag=true;
        for(int i=0 ; i<10;){
            if(i<8){
                System.out.println("shitutuya:"+"before");
                i++;
            }
            else if (i==8){
                if (flag){
                    System.out.println("shitutuya:"+"stop");
                    flag=false;
                }else {
                    System.out.println("shitutuya:"+"end");
                    i++;
                }

            }
        }*/

      /*
        List<Map<String, Object>> alarmOutCount=new ArrayList<>();
        List<Map<String, Object>> alarmInCount=new ArrayList<>();
        alarmOutCount.add((Map<String, Object>) new HashMap<>().put("1",2));

        System.out.println("shitutuya:"+alarmInCount.addAll(alarmOutCount));*/


      /*  int alarm= 5;

        int fcg = alarm / 4;
        int aqsj = fcg > 0 ? (alarm - 4) / 2 : alarm / 2;
        int syfh = fcg > 0 ? alarm - 6 : aqsj > 0 ? alarm - 2 : alarm;
        System.out.println("fcg:"+fcg+"==aqsj:"+aqsj+"==syfh:"+syfh +"==alarm:"+alarm);*/


        //测试list<>
        List<Map<String, Object>> list=new ArrayList<>();
        Map<String, Object> params1 = new HashMap();
        params1.put("id","22");
        params1.put("type","1");
        params1.put("upde_time","2021-06-01 12:00:00");
        Map<String, Object> params2 = new HashMap();
        params2.put("id","22");
        params2.put("type","2");
        params2.put("upde_time","2021-06-02 13:00:00");
        Map<String, Object> params3 = new HashMap();
        params3.put("id","22");
        params3.put("type","3");
        params3.put("upde_time","2021-06-03 14:00:00");
        list.add(params2);
        list.add(params1);
        list.add(params3);
        list.forEach(System.out::println);   //打印数据

        List<Map<String, Object>> list2 = list.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(
                                () ->new TreeSet<>(Comparator.comparing(m->m.get("id").toString()))
                        ),ArrayList::new
                )
        );    //根据value字段值去重，保留第一次放入list的map值
        System.out.println("--------");
        list2.forEach(System.out::println);

    }
}
